/*
 * @Author: lvyinling lvyinling@smartlink.com.cn
 * @Date: 2022-07-04 10:35:30
 * @LastEditors: lvyinling lvyinling@smartlink.com.cn
 * @LastEditTime: 2022-07-29 16:16:50
 * @FilePath: /react-vite-template/src/services/myOrder/index.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from "@/pages/p-rs/services/request";
import config from "./config";
import ENV from "@/pages/p-cnpc/config";
import { DTO, Params } from "./type";

// 我的订单列表
export function getMyOrderList(params: Params.ListSearchParams) {
  return axios.post<CNPC.Res.page<DTO.SearchMyOrder>>(
    config.getMyOrderList,
    params
  );
}

// 我的订单详情
export function getOrderDetail(params: { orderId: number }) {
  return axios.post<CNPC.Res.data<DTO.OrderDetail>>(
    config.getOrderDetail,
    params,
    { loading: true }
  );
}
// 查询订单支付状态
export function getPayOrderState(params: { orderId: number }) {
  return axios.post<CNPC.Res.data<number>>(config.getPayOrderStateUrl, params);
}

// 去支付
export function payOrder(params: Params.PayOrderParams) {
  const u = navigator.userAgent,
    app = navigator.appVersion;
  const isAndroid = u.indexOf("Android") > -1 || u.indexOf("Linux") > -1; //g
  const isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

  let type = "WAP";

  if (isAndroid) {
    type = "Android";
  } else if (isIOS) {
    type = "iOS";
  }

  return axios.post<CNPC.Res.data<DTO.PayOrder>>(config.payOrder, {
    ...params,
    ipAddress: (window as any)?.returnCitySN?.cip, // sohu ip服务
    type: type,
  }, { loading: true });
}
// 取消订单
export async function cancelOrder(params: { orderId: number }) {
  const res = await axios.post<CNPC.Res.data<null>>(config.cancelOrder, params);
  return res.data;
}

// 上传文件
export function uploadFile(params: any) {
  return axios.post<CNPC.Res.data<{ fullPath: string }>>(
    ENV.uploadFile + "",
    params
  );
}
// 上传文件
export async function getEnterpriseWechatPicture() {
  const res = await axios.post<CNPC.Res.data<{ fullPath: string }>>(
    config.getEnterpriseWechatPicture,
    {}
  );
  return res.data.data;
}
